mini.parse();
var grid = mini.get("datagrid1");
var url = bootPATH + "../frame/frame1/pages/";
$(function(){
	httpRequest();
});

function httpRequest(){
	
	var url = ajaxUrl  + '/socketUser/findBySocketUser.do';
	$.ajax({
		type    : 'post',
		url     : url,
		success : function (data){
			console.log(data);
			var messageData = data.data;
			if(messageData!=null){
				//用户状态
				for(var i = 0; i < messageData.length; i ++){
					if(messageData[i].messageStutas){
						messageData[i].messageStutas = messageData[i].messageStutas == 1 ? '未读消息' : '已读消息';
					}else{
						messageData[i].messageStutas = '';
					}
				}

				grid.setData(messageData);
			}else {
				console.log("当前无消息");
			}

		},
		error   : function (error){
			
		}
		
	})

}

function see() {
    var row = grid.getSelected();
    if (row) {
        mini.open({
            url: url +"message/MessageDetails.html",
            title: "编辑用户", width: 600, height: 400,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "edit", id: row.socketId };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
            	httpRequest();
            }
        });

    } else {
        mini.alert("请选中一条记录");
    }

}
//删除
function remove() {

	var rows=grid.getSelecteds();
	console.log(rows);
	if(rows.length>0){
		if (confirm("确定删除选中记录？")) {

			// for (var i = 0, l = rows.length; i < l; i++) {
			//     var r = rows[i];
			//     ids.push(r.socketId);
			// }
			// var id = ids.join(',');
			// ids.push(rows);
			ids=JSON.stringify(rows);
			console.log(ids);
			// grid.loading("操作中，请稍后......");
			$.ajax({
				url: ajaxUrl + "/socketUser/deleteMsg.do",
				type:"post",
				data:{
					ids:ids
				},
				success: function (text) {


					httpRequest();

					parent.unReadMsg();
					// parent.messageList();


				},
				error: function () {
					alert('失败')
				}
			});
		}
	}else{
		mini.alert("请选中要删除的数据")
	}
}

